package com.thanhnx.tlg1;

import model.Size;
import adapter.DataAdapter;
import android.app.Application;
import android.text.TextUtils;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;

public class MyApp extends Application {
	public static final String V = "■";
	public static final String N = "N";
	public static final String Y = "Y";
	public static final String FTL = "FTL";
	public static final String BBL = "BBL";

	public static final int MAX_ROW = 300;
	public static final int MAX_COL = 36;
	public DataAdapter dataAdapter;
	public TextView[][] tvViews;
	public EditText[] etViews;
	public String[][] datas;
	public String[][] hides;
	public int[] colA;
	public Size size;
	public int curMaxIndex = 1;

	@Override
	public void onCreate() {
		Log.e("MyApp", "Oncreate");
		size = new Size();
		etViews = new EditText[MAX_ROW];
		colA = new int[MAX_ROW];
		tvViews = new TextView[MAX_ROW][MAX_COL];
		datas = new String[MAX_ROW][MAX_COL];
		hides = new String[MAX_ROW][MAX_COL];
		initData();
		super.onCreate();
	}

	public void initData() {
		// ColA and datas and hides
		for (int i = 0; i < MAX_ROW; i++) {
			colA[i] = -1;
			for (int j = 0; j < MAX_COL; j++) {
				datas[i][j] = "";
				hides[i][j] = "";
			}
		}

		// hides
		hides[0][9] = FTL;
		hides[0][13] = FTL;
		hides[0][17] = FTL;
		hides[0][25] = FTL;
		hides[0][29] = FTL;
		hides[0][33] = FTL;

		hides[1][1] = FTL;
		hides[1][5] = FTL;
		hides[1][9] = FTL;
		hides[1][13] = FTL;
		hides[1][17] = FTL;
		hides[1][21] = FTL;
		hides[1][25] = FTL;
		hides[1][29] = FTL;
		hides[1][33] = FTL;
		//

	}

	public void setDataAdapter(DataAdapter adapter) {
		this.dataAdapter = adapter;
	}

	// Not use
	// public void createBlankData() {
	// size = new Size(MAX_ROW, MAX_COL);
	// for (int i = 0; i < size.row; i++) {
	// colA[i] = -1;
	// for (int j = 0; j < size.col; j++) {
	// datas[i][j] = "";
	// }
	// }
	// }

	// public void bindDataToView() {
	// dataAdapter.notifyDataSetChanged();
	// for (int i = 0; i < size.row; i++) {
	// if (colA[i] >= 0 && colA[i] < 37) {
	// etViews[i].setText(colA[i] + "");
	// }
	// for (int j = 0; j < size.col; j++) {
	// if (!TextUtils.isEmpty(datas[i][j])) {
	// tvViews[i][j].setText(datas[i][j]);
	// }
	// }
	// }
	// }

	// public void saveData() {
	// for (int i = 0; i < size.row; i++) {
	// String str = etViews[i].getText().toString();
	// if (!TextUtils.isEmpty(str)) {
	// // int input = -1;
	// // try {
	// // input = Integer.parseInt(str);
	// // } catch (Exception e) {
	// // }
	// int input = Integer.parseInt(str);
	// if (input >= 0 && input < 37) {
	// if (i + 1 > curMaxIndex) {
	// curMaxIndex = i + 1;
	// }
	// colA[i] = input;
	// // Log.e("savedata ", "colA["+i+"] = " + input );
	// }
	// }
	// // for (int j = 0; j < size.col; j++) {
	// // String s = tvViews[i][j].getText().toString();
	// // if (!TextUtils.isEmpty(s)) {
	// // datas[i][j] = s;
	// // }
	// // }
	// }
	// }
	//
	// public void update() {
	// saveData();
	// calculateData();
	// bindDataToView();
	// showtest(10);
	// }

	// nth 1-> max
	public void updateAt(int position) {
		Log.e("updateAt(int position)", " = " + position);
		if (position + 1 > curMaxIndex) {
			curMaxIndex = position + 1;
		}
		calculateData(position - 2, curMaxIndex);
		dataAdapter.notifyDataSetChanged();
		showtest(10);
	}

	public void calculateData(int from, int to) {
		Log.e("calculateData(int from  = from " + from + " to = " + to,
				"from to");

		if (from >= to) {
			return;
		}
		if (from < 0) {
			from = 0;
		}
		for (int i = from; i < to; i++) {
			if (colA[i] >= 0 && colA[i] < 37) {
				// cal hides
				if (i > 0) {
					calculateHideAt(i, 1);
					calculateHideAt(i, 2);
					calculateHideAt(i, 3);
					calculateHideAt(i, 0);

					calculateHideAt(i, 5);
					calculateHideAt(i, 6);
					calculateHideAt(i, 7);
					calculateHideAt(i, 4);

					calculateHideAt(i, 9);
					calculateHideAt(i, 10);
					calculateHideAt(i, 11);
					calculateHideAt(i, 8);

					calculateHideAt(i, 13);
					calculateHideAt(i, 14);
					calculateHideAt(i, 15);
					calculateHideAt(i, 12);

					calculateHideAt(i, 17);
					calculateHideAt(i, 18);
					calculateHideAt(i, 19);
					calculateHideAt(i, 16);

					calculateHideAt(i, 21);
					calculateHideAt(i, 22);
					calculateHideAt(i, 23);
					calculateHideAt(i, 20);

					calculateHideAt(i, 25);
					calculateHideAt(i, 26);
					calculateHideAt(i, 27);
					calculateHideAt(i, 24);

					calculateHideAt(i, 29);
					calculateHideAt(i, 30);
					calculateHideAt(i, 31);
					calculateHideAt(i, 28);

					calculateHideAt(i, 33);
					calculateHideAt(i, 34);
					calculateHideAt(i, 35);
					calculateHideAt(i, 32);
				}
				// cal datas
				for (int j = 0; j < MAX_COL; j++) {
					calculateDataAt(i, j);
				}
			}
		}
	}

	public void calculateDataAll() {
		Log.e("calculateDataAll", "curMax = " + curMaxIndex);
		for (int i = 0; i < curMaxIndex; i++) {
			if (colA[i] >= 0 && colA[i] < 37) {
				// cal hides
				if (i > 0) {
					calculateHideAt(i, 1);
					calculateHideAt(i, 2);
					calculateHideAt(i, 3);
					calculateHideAt(i, 0);

					calculateHideAt(i, 5);
					calculateHideAt(i, 6);
					calculateHideAt(i, 7);
					calculateHideAt(i, 4);

					calculateHideAt(i, 9);
					calculateHideAt(i, 10);
					calculateHideAt(i, 11);
					calculateHideAt(i, 8);

					calculateHideAt(i, 13);
					calculateHideAt(i, 14);
					calculateHideAt(i, 15);
					calculateHideAt(i, 12);

					calculateHideAt(i, 17);
					calculateHideAt(i, 18);
					calculateHideAt(i, 19);
					calculateHideAt(i, 16);

					calculateHideAt(i, 21);
					calculateHideAt(i, 22);
					calculateHideAt(i, 23);
					calculateHideAt(i, 20);

					calculateHideAt(i, 25);
					calculateHideAt(i, 26);
					calculateHideAt(i, 27);
					calculateHideAt(i, 24);

					calculateHideAt(i, 29);
					calculateHideAt(i, 30);
					calculateHideAt(i, 31);
					calculateHideAt(i, 28);

					calculateHideAt(i, 33);
					calculateHideAt(i, 34);
					calculateHideAt(i, 35);
					calculateHideAt(i, 32);
				}
				// cal datas
				for (int j = 0; j < MAX_COL; j++) {
					calculateDataAt(i, j);
				}
			}
		}
	}

	// Calculate at location (x-row,y-col)
	// x>=0, colA[x] >=0 ,colA[x] <37
	public void calculateDataAt(int x, int y) {
		Log.e("calculateDataAt " + x + " " + y, "cal...ing");
		int a = colA[x];
		switch (y) {
		// Module 1
		case 0:
			if (a == 1 || a == 3 || a == 5 || a == 7 || a == 9 || a == 12
					|| a == 14 || a == 16 || a == 18 || a == 19 || a == 21
					|| a == 23 || a == 25 || a == 27 || a == 30 || a == 32
					|| a == 34 || a == 36) {
				datas[x][y] = V;
			} else {
				datas[x][y] = "";
			}
			break;
		case 1:
			if (a == 2 || a == 4 || a == 6 || a == 8 || a == 10 || a == 11
					|| a == 13 || a == 15 || a == 17 || a == 20 || a == 22
					|| a == 24 || a == 26 || a == 28 || a == 29 || a == 31
					|| a == 33 || a == 35) {
				datas[x][y] = V;
			} else {
				datas[x][y] = "";
			}
			break;
		case 2:
			if (x == 0) {
				break;
			}
			// =IF(ISBLANK(A6);"";AK6)
			if (colA[x] == -1) {
				datas[x][y] = "";
			} else {
				datas[x][y] = hides[x][0];
			}
			break;
		case 3:
			if (x == 0) {
				break;
			}
			// =IF(ISBLANK(A6);"";AW6)
			if (colA[x] == -1) {
				datas[x][y] = "";
			} else {
				datas[x][y] = hides[x][12];
			}
			break;
		case 4:
			if (x == 0) {
				break;
			}
			// =IF(ISBLANK(A6);"";BI6)
			datas[x][y] = (colA[x] == -1) ? ("") : (hides[x][24]);
			break;
		case 5:
			if (x <= 1) {
				break;
			}
			// =IF(ISBLANK(A7);
			// "";
			// IF(
			// $A7=0;
			// G6-1;
			// IF(
			// C7=IF(
			// COUNTIF($A4:$A6;0)=3;
			// C1;
			// IF(
			// COUNTIF($A5:$A6;0)=0;
			// C5;
			// IF(
			// COUNTIF($A4:$A6;0)=3;
			// C2;
			// IF(
			// COUNTIF($A4:$A6;0)=2;
			// C3;
			// IF(COUNTIF($A4:$A6;0)=1;C4;C5))
			// )
			// )
			// );
			// G6+1;
			// G6-1
			// )
			// )
			// )
			// cur = G7
			if (colA[x] == -1) {
				datas[x][y] = "";
			} else {
				if (colA[x] == 0) {
					datas[x][y] = (isE(datas[x - 1][y])) ? ("-1") : (Integer
							.parseInt(datas[x - 1][y]) - 1 + "");// G6-1;
				} else {
					Log.e("datas[x][1].equals(getDatasCondition5(x, y))",
							datas[x][1] + " and " + getDatasCondition5(x, y));
					if (datas[x][1].equals(getDatasCondition5(x, y))) {// C7 =
																		// ...
						datas[x][y] = (isE(datas[x - 1][y])) ? ("1") : (Integer
								.parseInt(datas[x - 1][y]) + 1 + "");// G6+1
					} else {
						datas[x][y] = (isE(datas[x - 1][y])) ? ("-1")
								: (Integer.parseInt(datas[x - 1][y]) - 1 + "");// G6-1
					}
				}
			}

			break;
		case 6:
			if (x < 1) {
				break;
			}
			// =IF(ISBLANK(A6);"";IF($A6=0;H5-1;IF($A5<>0;IF(C5=C6;H5+1;H5-1);IF(C4=C6;H5+1;H5-1))))
			// cur = H6
			if (colA[x] == -1) {
				datas[x][y] = "";
			} else {
				// IF($A6=0;H5-1;IF($A5<>0;IF(C5=C6;H5+1;H5-1);IF(C4=C6;H5+1;H5-1)))
				if (isE(datas[x - 1][y])) {
					datas[x][y] = (colA[x] == 0) ? ("-1")
							: ((colA[x - 1] != 0) ? ((datas[x - 1][1]
									.equals(datas[x][1])) ? ("1") : ("-1"))
									: ((datas[x - 2][1].equals(datas[x][1])) ? ("1")
											: ("-1")));
				} else {
					datas[x][y] = (colA[x] == 0) ? (Integer
							.parseInt(datas[x - 1][y]) - 1 + "")
							: ((colA[x - 1] != 0) ? ((datas[x - 1][1]
									.equals(datas[x][1])) ? (Integer
									.parseInt(datas[x - 1][y]) + 1 + "")
									: (Integer.parseInt(datas[x - 1][y]) - 1 + ""))
									: ((datas[x - 2][1].equals(datas[x][1])) ? (Integer
											.parseInt(datas[x - 1][y]) + 1 + "")
											: (Integer
													.parseInt(datas[x - 1][y]) - 1 + "")));
				}
			}
			break;
		case 7:
			if (datas[x][0].equals(V)) {
				if (x > 0) {
					Log.d("special ", "Integer.parseInt(datas[x - 1][y]) = "
							+ Integer.parseInt(datas[x - 1][y]));
					datas[x][y] = Integer.parseInt(datas[x - 1][y]) + 1 + "";
				} else {
					datas[x][y] = "1";
				}
			} else {
				if (x > 0) {
					Log.d("special ", "Integer.parseInt(datas[x - 1][y]) = "
							+ Integer.parseInt(datas[x - 1][y]));
					datas[x][y] = Integer.parseInt(datas[x - 1][y]) - 1 + "";
				} else {
					datas[x][y] = "-1";
				}
			}
			break;
		case 8:
			if (datas[x][1].equals(V)) {
				if (x > 0) {
					datas[x][y] = Integer.parseInt(datas[x - 1][y]) + 1 + "";
				} else {
					datas[x][y] = "1";
				}
			} else {
				if (x > 0) {
					datas[x][y] = Integer.parseInt(datas[x - 1][y]) - 1 + "";
				} else {
					datas[x][y] = "-1";
				}
			}
			break;
		// Module 2
		case 9:
			if (a != 0 && a % 2 == 0) {// A chan va khac zero
				datas[x][y] = V;
			} else {
				datas[x][y] = "";
			}
			break;
		case 10:
			if (a != 0 && a % 2 != 0) {// A le va khac zero
				datas[x][y] = V;
			} else {
				datas[x][y] = "";
			}
			break;
		case 11:// similar 2
			// datas[x][y] = datas[x][y - 9];
			if (x == 0) {
				break;
			}
			// =IF(ISBLANK(A6);"";AO6)
			if (colA[x] == -1) {
				datas[x][y] = "";
			} else {
				datas[x][y] = hides[x][4];
			}
			break;
		case 12: // /similar 3
			if (x == 0) {
				break;
			}
			// =IF(ISBLANK(A6);"";BA6)
			if (colA[x] == -1) {
				datas[x][y] = "";
			} else {
				datas[x][y] = hides[x][16];
			}
			break;
		case 13:// similar 4
			if (x == 0) {
				break;
			}
			// =IF(ISBLANK(A6);"";BM6)
			datas[x][y] = (colA[x] == -1) ? ("") : (hides[x][28]);
			break;
		case 14: //similar 5
			//=IF(ISBLANK(A7);"";IF($A7=0;G6-1;IF(C7=IF(COUNTIF($A4:$A6;0)=3;C1;IF(COUNTIF($A5:$A6;0)=0;C5;IF(COUNTIF($A4:$A6;0)=3;C2;IF(COUNTIF($A4:$A6;0)=2;C3;IF(COUNTIF($A4:$A6;0)=1;C4;C5)))));G6+1;G6-1)))//old
			//=IF(ISBLANK(A7);"";IF($A7=0;P6-1;IF(L7=IF(COUNTIF($A4:$A6;0)=3;L1;IF(COUNTIF($A5:$A6;0)=0;L5;IF(COUNTIF($A4:$A6;0)=3;L2;IF(COUNTIF($A4:$A6;0)=2;L3;IF(COUNTIF($A4:$A6;0)=1;L4;L5)))));P6+1;P6-1)))
			if (x <= 1) {
				break;
			}
			// cur = P7
			if (colA[x] == -1) {
				datas[x][y] = "";
			} else {
				if (colA[x] == 0) {
					datas[x][y] = (isE(datas[x - 1][y])) ? ("-1") : (Integer
							.parseInt(datas[x - 1][y]) - 1 + "");// P6-1;
				} else {
					Log.e("datas[x][10].equals(getDatasCondition10(x, y))",
							datas[x][10] + " and " + getDatasCondition10(x, y));
					if (datas[x][10].equals(getDatasCondition10(x, y))) {// L7 =
																		// ...
						datas[x][y] = (isE(datas[x - 1][y])) ? ("1") : (Integer
								.parseInt(datas[x - 1][y]) + 1 + "");// P6+1
					} else {
						datas[x][y] = (isE(datas[x - 1][y])) ? ("-1")
								: (Integer.parseInt(datas[x - 1][y]) - 1 + "");// P6-1
					}
				}
			}

			break;
		case 15://similar 6
			if (x < 1) {
				break;
			}
			// =IF(ISBLANK(A6);"";IF($A6=0;H5-1;IF($A5<>0;IF(C5=C6;H5+1;H5-1);IF(C4=C6;H5+1;H5-1)))) //old
			// =IF(ISBLANK(A6);"";IF($A6=0;Q5-1;IF($A5<>0;IF(L5=L6;Q5+1;Q5-1);IF(L4=L6;Q5+1;Q5-1)))) 
			// cur = Q6
			if (colA[x] == -1) {
				datas[x][y] = "";
			} else {
				if (isE(datas[x - 1][y])) {
					datas[x][y] = (colA[x] == 0) ? ("-1")
							: ((colA[x - 1] != 0) ? ((datas[x - 1][10]
									.equals(datas[x][10])) ? ("1") : ("-1"))
									: ((datas[x - 2][10].equals(datas[x][10])) ? ("1")
											: ("-1")));
				} else {
					datas[x][y] = (colA[x] == 0) ? (Integer
							.parseInt(datas[x - 1][y]) - 1 + "")
							: ((colA[x - 1] != 0) ? ((datas[x - 1][10]
									.equals(datas[x][10])) ? (Integer
									.parseInt(datas[x - 1][y]) + 1 + "")
									: (Integer.parseInt(datas[x - 1][y]) - 1 + ""))
									: ((datas[x - 2][10].equals(datas[x][10])) ? (Integer
											.parseInt(datas[x - 1][y]) + 1 + "")
											: (Integer
													.parseInt(datas[x - 1][y]) - 1 + "")));
				}
			}
			break;
		case 16:
			if (datas[x][9].equals(V)) {
				if (x > 0) {
					datas[x][y] = Integer.parseInt(datas[x - 1][y]) + 1 + "";
				} else {
					datas[x][y] = "1";
				}
			} else {
				if (x > 0) {
					datas[x][y] = Integer.parseInt(datas[x - 1][y]) - 1 + "";
				} else {
					datas[x][y] = "-1";
				}
			}
			break;
		case 17:
			if (datas[x][10].equals(V)) {
				if (x > 0) {
					datas[x][y] = Integer.parseInt(datas[x - 1][y]) + 1 + "";
				} else {
					datas[x][y] = "1";
				}
			} else {
				if (x > 0) {
					datas[x][y] = Integer.parseInt(datas[x - 1][y]) - 1 + "";
				} else {
					datas[x][y] = "-1";
				}
			}
			break;
		case 18:
			if (a >= 19) {
				datas[x][y] = V;
			} else {
				datas[x][y] = "";
			}
			break;
		case 19:
			if (a > 0 && a <= 18) {
				datas[x][y] = V;
			} else {
				datas[x][y] = "";
			}
			break;
		case 20:
			if (x == 0) {
				break;
			}
			// =IF(ISBLANK(A6);"";AS6)
			if (colA[x] == -1) {
				datas[x][y] = "";
			} else {
				datas[x][y] = hides[x][8];
			}
			break;
		case 21:
			if (x == 0) {
			break;
		}
		// =IF(ISBLANK(A6);"";BE6)
		if (colA[x] == -1) {
			datas[x][y] = "";
		} else {
			datas[x][y] = hides[x][20];
		}
		break;
		case 22:
			if (x == 0) {
				break;
			}
			// =IF(ISBLANK(A6);"";BQ6)
			datas[x][y] = (colA[x] == -1) ? ("") : (hides[x][32]);
			break;
		case 23:
			//=IF(ISBLANK(A7);"";IF($A7=0;P6-1;IF(L7=IF(COUNTIF($A4:$A6;0)=3;L1;IF(COUNTIF($A5:$A6;0)=0;L5;IF(COUNTIF($A4:$A6;0)=3;L2;IF(COUNTIF($A4:$A6;0)=2;L3;IF(COUNTIF($A4:$A6;0)=1;L4;L5)))));P6+1;P6-1))) //old
			//=IF(ISBLANK(A7);"";IF($A7=0;Y6-1;IF(U7=IF(COUNTIF($A4:$A6;0)=3;U1;IF(COUNTIF($A5:$A6;0)=0;U5;IF(COUNTIF($A4:$A6;0)=3;U2;IF(COUNTIF($A4:$A6;0)=2;U3;IF(COUNTIF($A4:$A6;0)=1;U4;U5)))));Y6+1;Y6-1)))
			if (x <= 1) {
				break;
			}
			// cur = Y7
			if (colA[x] == -1) {
				datas[x][y] = "";
			} else {
				if (colA[x] == 0) {
					datas[x][y] = (isE(datas[x - 1][y])) ? ("-1") : (Integer
							.parseInt(datas[x - 1][y]) - 1 + "");// Y6-1;
				} else {
					Log.e("datas[x][19].equals(getDatasCondition19(x, y))",
							datas[x][19] + " and " + getDatasCondition19(x, y));
					if (datas[x][19].equals(getDatasCondition19(x, y))) {// U7 =
																		// ...
						datas[x][y] = (isE(datas[x - 1][y])) ? ("1") : (Integer
								.parseInt(datas[x - 1][y]) + 1 + "");// Y6+1
					} else {
						datas[x][y] = (isE(datas[x - 1][y])) ? ("-1")
								: (Integer.parseInt(datas[x - 1][y]) - 1 + "");// Y6-1
					}
				}
			}

			break;
		case 24:
			if (x < 1) {
				break;
			}
			// =IF(ISBLANK(A6);"";IF($A6=0;Q5-1;IF($A5<>0;IF(L5=L6;Q5+1;Q5-1);IF(L4=L6;Q5+1;Q5-1)))) //old
			// =IF(ISBLANK(A6);"";IF($A6=0;Z5-1;IF($A5<>0;IF(U5=U6;Z5+1;Z5-1);IF(U4=U6;Z5+1;Z5-1))))
			// cur = Z6
			if (colA[x] == -1) {
				datas[x][y] = "";
			} else {
				if (isE(datas[x - 1][y])) {
					datas[x][y] = (colA[x] == 0) ? ("-1")
							: ((colA[x - 1] != 0) ? ((datas[x - 1][19]
									.equals(datas[x][19])) ? ("1") : ("-1"))
									: ((datas[x - 2][19].equals(datas[x][19])) ? ("1")
											: ("-1")));
				} else {
					datas[x][y] = (colA[x] == 0) ? (Integer
							.parseInt(datas[x - 1][y]) - 1 + "")
							: ((colA[x - 1] != 0) ? ((datas[x - 1][19]
									.equals(datas[x][19])) ? (Integer
									.parseInt(datas[x - 1][y]) + 1 + "")
									: (Integer.parseInt(datas[x - 1][y]) - 1 + ""))
									: ((datas[x - 2][19].equals(datas[x][19])) ? (Integer
											.parseInt(datas[x - 1][y]) + 1 + "")
											: (Integer
													.parseInt(datas[x - 1][y]) - 1 + "")));
				}
			}
			break;
		case 25:
			if (datas[x][18].equals(V)) {
				if (x > 0) {
					datas[x][y] = Integer.parseInt(datas[x - 1][y]) + 1 + "";
				} else {
					datas[x][y] = "1";
				}
			} else {
				if (x > 0) {
					datas[x][y] = Integer.parseInt(datas[x - 1][y]) - 1 + "";
				} else {
					datas[x][y] = "-1";
				}
			}
			break;
		case 26:
			if (datas[x][19].equals(V)) {
				if (x > 0) {
					datas[x][y] = Integer.parseInt(datas[x - 1][y]) + 1 + "";
				} else {
					datas[x][y] = "1";
				}
			} else {
				if (x > 0) {
					datas[x][y] = Integer.parseInt(datas[x - 1][y]) - 1 + "";
				} else {
					datas[x][y] = "-1";
				}
			}
			break;
		default:
			break;
		}

	}

	// x>= 1
	public void calculateHideAt(int x, int y) {
		// Log.e("calculateHideAt ", x + " " + y);
		// int a = colA[x];
		switch (y) {
		// Module 1
		case 0:
			if (hides[x][y + 3].equals(Y)) {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) + 1 + "";
				}
			} else {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "-1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) - 1 + "";
				}
			}
			break;
		case 1:
			if (x >= 2) {// =IF(ISBLANK(A8);"";IF(A7=0;AL7;IF(AN7<>"Y";IF(AL7="BBL";"FTL";"BBL");AL7)))
				if (colA[x] == -1) {
					hides[x][y] = "";
				} else {
					if (colA[x - 1] == 0) {
						hides[x][y] = hides[x - 1][y];
					} else {
						if (!hides[x - 1][y + 2].equals(Y)) {
							if (hides[x - 1][y].equals(BBL)) {
								hides[x][y] = FTL;
							} else {
								hides[x][y] = BBL;
							}
						} else {
							hides[x][y] = hides[x - 1][y];
						}
					}
				}
			}
			break;
		case 2:
			if (x == 1) {
				// C5
				hides[x][y] = datas[x - 1][1];
				break;
			}
			if (x == 2) {
				// =IF(ISBLANK($A7);"";IF(AL7="FTL";IF($A6=0;IF(AND($A6=0;$A5=0);$C4;$C5);$C6);IF($A6=0;IF(AND($A6=0;$A5=0);$C3;$C4);$C5)))
				if (isE(colA[x] + "")) {
					hides[x][y] = "";
				} else {
					if (hides[x][y - 1].equals(FTL)) {
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								hides[x][y] = "";// =C4
							} else {
								hides[x][y] = datas[x - 2][1];
							}
						} else {
							hides[x][y] = datas[x - 1][1];// C6
						}
					} else {
						// ;IF($A6=0;IF(AND($A6=0;$A5=0);$C3;$C4);$C5)))
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								hides[x][y] = "";// C3;
							} else {
								hides[x][y] = "";// C4;
							}
						} else {
							hides[x][y] = datas[0][1];// C5
						}
					}
				}
				break;
			}
			if (x >= 3) {
				// =IF(ISBLANK($A8);"";IF(AL8="FTL";IF($A7=0;IF(AND($A7=0;$A6=0);$C5;$C6);$C7);IF($A7=0;IF(AND($A7=0;$A6=0);$C4;$C5);$C6)))
				if (isE(colA[x] + "")) {
					hides[x][y] = "";
				} else {
					if (hides[x][y - 1].equals(FTL)) {
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								hides[x][y] = datas[x - 3][1];// =C5
							} else {
								hides[x][y] = datas[x - 2][1];// C6
							}
						} else {
							hides[x][y] = datas[x - 1][1];// C7
						}
					} else {
						// IF($A7=0;IF(AND($A7=0;$A6=0);$C4;$C5);$C6)))
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								if (x == 3) {
									hides[x][y] = "";// C4
								} else {
									hides[x][y] = datas[x - 4][1];// C4
								}
							} else {
								hides[x][y] = datas[x - 3][1];// C5;
							}
						} else {
							hides[x][y] = datas[x - 2][1];// C6;
						}
					}
				}
			}
			break;
		case 3:
			if (colA[x] == 0) {
				hides[x][y] = N;
			} else {
				if (hides[x][y - 1].equals(datas[x][1])) {
					hides[x][y] = Y;
				} else {
					hides[x][y] = N;
				}
			}
			break;// Mudule 2
		case 4:// =IF(AR6="Y";AO5+1;AO5-1)
			if (hides[x][y + 3].equals(Y)) {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) + 1 + "";
				}
			} else {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "-1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) - 1 + "";
				}
			}
			break;
		case 5:
			if (x >= 2) {
				// IF($A6=0;AP6;IF(AR6<>"Y";IF(AP6="BBL";"FTL";"BBL");AP6)))
				if (colA[x - 1] == 0) {
					hides[x][y] = hides[x - 1][y];
				} else {
					if (!hides[x - 1][y + 2].equals(Y)) {
						if (hides[x - 1][y].equals(BBL)) {
							hides[x][y] = FTL;
						} else {
							hides[x][y] = BBL;
						}
					} else {
						hides[x][y] = hides[x - 1][y];
					}

				}
			}
			break;
		case 6:
			if (x == 1) {
				hides[x][y] = datas[x - 1][10];// L5
				break;
			}
			if (x == 2) {
				// =IF(ISBLANK($A7);"";IF(AP7="FTL";IF($A6=0;IF(AND($A6=0;$A5=0);$C4;$C5);$C6);IF($A6=0;IF(AND($A6=0;$A5=0);$C3;$C4);$C5)))
				if (isE(colA[x] + "")) {
					hides[x][y] = "";
				} else {
					if (hides[x][y - 1].equals(FTL)) {
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								hides[x][y] = "";// =C4
							} else {
								hides[x][y] = datas[x - 2][1];
							}
						} else {
							hides[x][y] = datas[x - 1][1];// C6
						}
					} else {
						// ;IF($A6=0;IF(AND($A6=0;$A5=0);$C3;$C4);$C5)))
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								hides[x][y] = "";// C3;
							} else {
								hides[x][y] = "";// C4;
							}
						} else {
							hides[x][y] = datas[0][1];// C5
						}
					}
				}
				break;
			}
			if (x >= 3) {
				// =IF(ISBLANK($A7);"";IF(AP7="FTL";IF($A6=0;IF(AND($A6=0;$A5=0);$C4;$C5);$C6);IF($A6=0;IF(AND($A6=0;$A5=0);$C3;$C4);$C5)))
				if (isE(colA[x] + "")) {
					hides[x][y] = "";
				} else {
					if (hides[x][y - 1].equals(FTL)) {
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								hides[x][y] = datas[x - 3][1];// =C5
							} else {
								hides[x][y] = datas[x - 2][1];// C6
							}
						} else {
							hides[x][y] = datas[x - 1][1];// C7
						}
					} else {
						// IF($A7=0;IF(AND($A7=0;$A6=0);$C4;$C5);$C6)))
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								if (x == 3) {
									hides[x][y] = "";// C4
								} else {
									hides[x][y] = datas[x - 4][1];// C4
								}
							} else {
								hides[x][y] = datas[x - 3][1];// C5;
							}
						} else {
							hides[x][y] = datas[x - 2][1];// C6;
						}
					}
				}
			}
			break;
		case 7:// =IF($A6=0;"N";IF(AQ6=$L6;"Y";"N"))
			if (colA[x] == 0) {
				hides[x][y] = N;
			} else {
				if (hides[x][y - 1].equals(datas[x][10])) {
					hides[x][y] = Y;
				} else {
					hides[x][y] = N;
				}
			}
			break;
		// Module 3
		case 8:// =IF(ISBLANK(A7);"";IF(AV7="Y";AS6+1;AS6-1))
			if (hides[x][y + 3].equals(Y)) {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) + 1 + "";
				}
			} else {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "-1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) - 1 + "";
				}
			}
			break;
		case 9:// =IF(ISBLANK(A7);"";IF($A6=0;AT6;IF(AV6<>"Y";IF(AT6="BBL";"FTL";"BBL");AT6)))
			if (x >= 2) {
				if (colA[x] == -1) {
					hides[x][y] = "";
				} else {
					if (colA[x - 1] == 0) {
						hides[x][y] = hides[x - 1][y];
					} else {
						if (!hides[x - 1][y + 2].equals(Y)) {
							if (hides[x - 1][y].equals(BBL)) {
								hides[x][y] = FTL;
							} else {
								hides[x][y] = BBL;
							}
						} else {
							hides[x][y] = hides[x - 1][y];
						}
					}
				}
			}
			break;
		case 10:
			if (x == 1) {
				// U5
				hides[x][y] = datas[x - 1][19];
				break;
			}
			if (x == 2) {
				// =IF(ISBLANK($A7);"";IF(AT7="FTL";IF($A6=0;IF(AND($U6=0;$U5=0);$U4;$U5);$C6);IF($A6=0;IF(AND($A6=0;$A5=0);$U2;$U3);$U5)))
				if (isE(colA[x] + "")) {
					hides[x][y] = "";
				} else {
					if (hides[x][y - 1].equals(FTL)) {
						// IF($A6=0;IF(AND($U6=0;$U5=0);$U4;$U5);$C6)
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								hides[x][y] = "";// =U4
							} else {
								hides[x][y] = datas[x - 2][19];// U5
							}
						} else {
							hides[x][y] = datas[x - 1][1];// C6
						}
					} else {
						// ;IF($A6=0;IF(AND($A6=0;$A5=0);$U2;$U3);$U5)
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								hides[x][y] = "";// U3;
							} else {
								hides[x][y] = "";// U4;
							}
						} else {
							hides[x][y] = datas[0][19];// U5
						}
					}
				}
				break;
			}
			if (x >= 3) {
				// =IF(ISBLANK($A8);"";IF(AT8="FTL";IF($A7=0;IF(AND($U7=0;$U6=0);$U5;$U6);$C7);IF($A7=0;IF(AND($A7=0;$A6=0);$U3;$U4);$U6)))
				if (isE(colA[x] + "")) {
					hides[x][y] = "";
				} else {
					if (hides[x][y - 1].equals(FTL)) {
						// IF($A7=0;IF(AND($U7=0;$U6=0);$U5;$U6);$C7)
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								hides[x][y] = datas[x - 3][19];// =U5
							} else {
								hides[x][y] = datas[x - 2][19];// U6
							}
						} else {
							hides[x][y] = datas[x - 1][1];// C7
						}
					} else {
						// IF($A7=0;IF(AND($A7=0;$A6=0);$U3;$U4);$U6)))
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								if (x == 3) {
									hides[x][y] = "";// U4
								} else {
									hides[x][y] = datas[x - 4][19];// U4
								}
							} else {
								hides[x][y] = datas[x - 3][19];// U5;
							}
						} else {
							hides[x][y] = datas[x - 2][19];// U6;
						}
					}
				}
			}
			break;
		case 11:// =IF($A6=0;"N";IF(AU6=$U6;"Y";"N"))
			if (colA[x] == 0) {
				hides[x][y] = N;
			} else {
				if (hides[x][y - 1].equals(datas[x][19])) {
					hides[x][y] = Y;
				} else {
					hides[x][y] = N;
				}
			}
			break;
		// Module 4
		case 12:// =IF(ISBLANK(A7);"";IF(AZ7="Y";AW6+1;AW6-1))
			if (hides[x][y + 3].equals(Y)) {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) + 1 + "";
				}
			} else {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "-1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) - 1 + "";
				}
			}
			break;
		case 13:// =IF(ISBLANK(A7);"";IF($A6=0;AX6;IF(AZ6="N";IF(AX6="BBL";"FTL";IF(AND(AZ5="N";AX5<>"BBL";IF(COUNTIF($A4:$A6;0)=1;AND(AZ4="N";AX4<>"BBL");TRUE);IF(COUNTIF($A4:$A6;0)=2;AND(AZ4="N";AZ3="N";AX4<>"BBL";
			if (x >= 2) {
				if (colA[x] == -1) {
					hides[x][y] = "";
				} else {// IF($A6=0
					if (colA[x - 1] == 0) {
						hides[x][y] = hides[x - 1][y];
					} else {
						if (hides[x - 1][y + 2].equals(N)) {
							// IF(AX6="BBL";"FTL";IF(AND(AZ5="N";AX5<>"BBL";IF(COUNTIF($A4:$A6;0)=1;AND(AZ4="N";AX4<>"BBL");TRUE);IF(COUNTIF($A4:$A6;0)=2;AND(AZ4="N";AZ3="N";AX4<>"BBL";AX3<>"BBL");TRUE));"BBL";"FTL"))
							if (hides[x - 1][y].equals(BBL)) {
								hides[x][y] = FTL;
							} else {
								if (getHidesCondition13(x, y)) {
									hides[x][y] = BBL;
								} else {
									hides[x][y] = FTL;
								}
							}
						} else {
							hides[x][y] = hides[x - 1][y];
						}
					}
				}
			}
			break;
		case 14:
			if (x == 1) {
				hides[x][y] = datas[x - 1][1];// C5
				break;
			}
			if (x == 2) {
				// =IF(ISBLANK($A7);"";IF(AP7="FTL";IF($A6=0;IF(AND($A6=0;$A5=0);$C4;$C5);$C6);IF($A6=0;IF(AND($A6=0;$A5=0);$C3;$C4);$C5)))
				if (isE(colA[x] + "")) {
					hides[x][y] = "";
				} else {
					if (hides[x][y - 1].equals(FTL)) {
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								hides[x][y] = "";// =C4
							} else {
								hides[x][y] = datas[x - 2][1];// C5
							}
						} else {
							hides[x][y] = datas[x - 1][1];// C6
						}
					} else {
						// ;IF($A6=0;IF(AND($A6=0;$A5=0);$C3;$C4);$C5)))
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								hides[x][y] = "";// C3;
							} else {
								hides[x][y] = "";// C4;
							}
						} else {
							hides[x][y] = datas[0][1];// C5
						}
					}
				}
				break;
			}
			if (x >= 3) {
				// =IF(ISBLANK($A7);"";IF(AP7="FTL";IF($A6=0;IF(AND($A6=0;$A5=0);$C4;$C5);$C6);IF($A6=0;IF(AND($A6=0;$A5=0);$C3;$C4);$C5)))
				if (isE(colA[x] + "")) {
					hides[x][y] = "";
				} else {
					if (hides[x][y - 1].equals(FTL)) {
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								hides[x][y] = datas[x - 3][1];// =C5
							} else {
								hides[x][y] = datas[x - 2][1];// C6
							}
						} else {
							hides[x][y] = datas[x - 1][1];// C7
						}
					} else {
						// IF($A7=0;IF(AND($A7=0;$A6=0);$C4;$C5);$C6)))
						if (colA[x - 1] == 0) {
							if (colA[x - 2] == 0) {
								if (x == 3) {
									hides[x][y] = "";// C4
								} else {
									hides[x][y] = datas[x - 4][1];// C4
								}
							} else {
								hides[x][y] = datas[x - 3][1];// C5;
							}
						} else {
							hides[x][y] = datas[x - 2][1];// C6;
						}
					}
				}
			}
			break;
		case 15:// =IF(ISBLANK(A7);"";IF($A7=0;"N";IF(AY7=$C7;"Y";"N")))
			if (colA[x] == 0) {
				hides[x][y] = N;
			} else {
				if (hides[x][y - 1].equals(datas[x][1])) {// C7
					hides[x][y] = Y;
				} else {
					hides[x][y] = N;
				}
			}
			break;
		// Module 5
		case 16:
			if (hides[x][y + 3].equals(Y)) {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) + 1 + "";
				}
			} else {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "-1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) - 1 + "";
				}
			}
			break;
		case 17:
			if (x >= 2) {
				if (colA[x] == -1) {
					hides[x][y] = "";
				} else {// IF($A6=0
					if (colA[x - 1] == 0) {
						hides[x][y] = hides[x - 1][y];
					} else {
						if (hides[x - 1][y + 2].equals(N)) {
							// IF(AX6="BBL";"FTL";IF(AND(AZ5="N";AX5<>"BBL";IF(COUNTIF($A4:$A6;0)=1;AND(AZ4="N";AX4<>"BBL");TRUE);IF(COUNTIF($A4:$A6;0)=2;AND(AZ4="N";AZ3="N";AX4<>"BBL";AX3<>"BBL");TRUE));"BBL";"FTL"))
							if (hides[x - 1][y].equals(BBL)) {
								hides[x][y] = FTL;
							} else {
								if (getHidesCondition13(x, y)) {
									hides[x][y] = BBL;
								} else {
									hides[x][y] = FTL;
								}
							}
						} else {
							hides[x][y] = hides[x - 1][y];
						}
					}
				}
			}
			break;
		case 18:
			if (x == 1) {
				hides[x][y] = datas[x - 1][10];// L5
				break;
			}
			if (x == 2) {// cur = BC7
				// IF(BB7="FTL";IF($A6=0;$L5;$L6);IF($A6=0;$L3;$L5)))
				hides[x][y] = (hides[x][y - 1].equals(FTL)) ? ((colA[x - 1] == 0) ? (datas[x - 2][10])
						: (datas[x - 1][10]))
						: ((colA[x - 1] == 0) ? ("") : (datas[x - 2][10]));
				break;
			}
			if (x >= 3) {// cur = BC8
				hides[x][y] = (hides[x][y - 1].equals(FTL)) ? ((colA[x - 1] == 0) ? (datas[x - 2][10])
						: (datas[x - 1][10]))
						: ((colA[x - 1] == 0) ? (datas[x - 4][10])
								: (datas[x - 2][10]));
			}
			break;
		case 19:// =IF($A6=0;"N";IF(BC6=$L6;"Y";"N"))
			if (colA[x] == 0) {
				hides[x][y] = N;
			} else {
				if (hides[x][y - 1].equals(datas[x][10])) {// L6
					hides[x][y] = Y;
				} else {
					hides[x][y] = N;
				}
			}
			break;
		// Module 6
		case 20:
			if (hides[x][y + 3].equals(Y)) {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) + 1 + "";
				}
			} else {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "-1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) - 1 + "";
				}
			}
			break;
		case 21:
			if (x >= 2) {
				if (colA[x] == -1) {
					hides[x][y] = "";
				} else {// IF($A6=0
					if (colA[x - 1] == 0) {
						hides[x][y] = hides[x - 1][y];
					} else {
						if (hides[x - 1][y + 2].equals(N)) {
							// IF(AX6="BBL";"FTL";IF(AND(AZ5="N";AX5<>"BBL";IF(COUNTIF($A4:$A6;0)=1;AND(AZ4="N";AX4<>"BBL");TRUE);IF(COUNTIF($A4:$A6;0)=2;AND(AZ4="N";AZ3="N";AX4<>"BBL";AX3<>"BBL");TRUE));"BBL";"FTL"))
							if (hides[x - 1][y].equals(BBL)) {
								hides[x][y] = FTL;
							} else {
								if (getHidesCondition13(x, y)) {
									hides[x][y] = BBL;
								} else {
									hides[x][y] = FTL;
								}
							}
						} else {
							hides[x][y] = hides[x - 1][y];
						}
					}
				}
			}
			break;
		case 22:
			if (x == 1) {
				hides[x][y] = datas[x - 1][19];// U5
				break;
			}
			if (x == 2) {// cur = BG7
				// =IF(ISBLANK(A7);"";IF(BF7="FTL";IF($A6=0;$U5;$U6);IF($A6=0;$U3;$U5)))
				hides[x][y] = (hides[x][y - 1].equals(FTL)) ? ((colA[x - 1] == 0) ? (datas[x - 2][19])
						: (datas[x - 1][19]))
						: ((colA[x - 1] == 0) ? ("") : (datas[x - 2][19]));
				break;
			}
			if (x >= 3) {// cur = BG8
				hides[x][y] = (hides[x][y - 1].equals(FTL)) ? ((colA[x - 1] == 0) ? (datas[x - 2][19])
						: (datas[x - 1][19]))
						: ((colA[x - 1] == 0) ? (datas[x - 4][19])
								: (datas[x - 2][19]));
				// Log.e("at "+x +" 22 = " , hides[x][y]);
			}
			break;
		case 23:// =IF($A6=0;"N";IF(BG6=$U6;"Y";"N"))
			if (colA[x] == 0) {
				hides[x][y] = N;
			} else {
				if (hides[x][y - 1].equals(datas[x][19])) {// U6
					hides[x][y] = Y;
				} else {
					hides[x][y] = N;
				}
			}
			break;
		// Module 7
		case 24:
			if (hides[x][y + 3].equals(Y)) {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) + 1 + "";
				}
			} else {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "-1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) - 1 + "";
				}
			}
			break;
		case 25:
			if (x >= 2) {
				if (colA[x] == -1) {
					hides[x][y] = "";
				} else {// IF($A6=0
					if (colA[x - 1] == 0) {
						hides[x][y] = hides[x - 1][y];
					} else {
						if (hides[x - 1][y + 2].equals(N)) {
							// IF(AX6="BBL";"FTL";IF(AND(AZ5="N";AX5<>"BBL";IF(COUNTIF($A4:$A6;0)=1;AND(AZ4="N";AX4<>"BBL");TRUE);IF(COUNTIF($A4:$A6;0)=2;AND(AZ4="N";AZ3="N";AX4<>"BBL";AX3<>"BBL");TRUE));"BBL";"FTL"))
							if (hides[x - 1][y].equals(BBL)) {
								hides[x][y] = FTL;
							} else {
								if (getHidesCondition25(x, y)) {
									hides[x][y] = BBL;
								} else {
									hides[x][y] = FTL;
								}
							}
						} else {
							hides[x][y] = hides[x - 1][y];
						}
					}
				}
			}
			break;
		case 26:
			if (x == 1) {
				hides[x][y] = datas[x - 1][1];// C5
			} else {// cur = BK7
					// =IF(ISBLANK(A7);"";IF(BJ7="FTL";IF($A6=0;$C5;$C6);IF($A6=0;$C4;$C5)))
				hides[x][y] = (hides[x][y - 1].equals(FTL)) ? ((colA[x - 1] == 0) ? (datas[x - 2][1])
						: (datas[x - 1][1]))
						: ((colA[x - 1] == 0) ? (datas[x - 3][1])
								: (datas[x - 2][1]));
			}
			break;
		case 27:// =IF($A6=0;"N";IF(BG6=$C6;"Y";"N"))
			if (colA[x] == 0) {
				hides[x][y] = N;
			} else {
				if (hides[x][y - 1].equals(datas[x][1])) {// C6
					hides[x][y] = Y;
				} else {
					hides[x][y] = N;
				}
			}
			break;
		// Module 8
		case 28:
			if (hides[x][y + 3].equals(Y)) {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) + 1 + "";
				}
			} else {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "-1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) - 1 + "";
				}
			}
			break;
		case 29:
			if (x >= 2) {
				if (colA[x] == -1) {
					hides[x][y] = "";
				} else {// IF($A6=0
					if (colA[x - 1] == 0) {
						hides[x][y] = hides[x - 1][y];
					} else {
						if (hides[x - 1][y + 2].equals(N)) {
							if (hides[x - 1][y].equals(BBL)) {
								hides[x][y] = FTL;
							} else {
								if (getHidesCondition25(x, y)) {
									hides[x][y] = BBL;
								} else {
									hides[x][y] = FTL;
								}
							}
						} else {
							hides[x][y] = hides[x - 1][y];
						}
					}
				}
			}
			break;
		case 30:
			if (x == 1) {
				hides[x][y] = datas[x - 1][10];// L5
			} else {// cur = B07
					// =IF(ISBLANK(A7);"";IF(BN7="FTL";IF($A6=0;$L5;$L6);IF($A6=0;$L4;$L5)))
				hides[x][y] = (hides[x][y - 1].equals(FTL)) ? ((colA[x - 1] == 0) ? (datas[x - 2][10])
						: (datas[x - 1][10]))
						: ((colA[x - 1] == 0) ? (datas[x - 3][10])
								: (datas[x - 2][10]));
			}
			break;
		case 31:// =IF($A6=0;"N";IF(BO6=$L6;"Y";"N"))
			if (colA[x] == 0) {
				hides[x][y] = N;
			} else {
				if (hides[x][y - 1].equals(datas[x][10])) {// L6
					hides[x][y] = Y;
				} else {
					hides[x][y] = N;
				}
			}
			break;
		// module 9
		case 32:
			if (hides[x][y + 3].equals(Y)) {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) + 1 + "";
				}
			} else {
				if (isE(hides[x - 1][y])) {
					hides[x][y] = "-1";
				} else {
					hides[x][y] = Integer.parseInt(hides[x - 1][y]) - 1 + "";
				}
			}
			break;
		case 33:
			if (x >= 2) {
				if (colA[x] == -1) {
					hides[x][y] = "";
				} else {// IF($A6=0
					if (colA[x - 1] == 0) {
						hides[x][y] = hides[x - 1][y];
					} else {
						if (hides[x - 1][y + 2].equals(N)) {
							if (hides[x - 1][y].equals(BBL)) {
								hides[x][y] = FTL;
							} else {
								if (getHidesCondition25(x, y)) {
									hides[x][y] = BBL;
								} else {
									hides[x][y] = FTL;
								}
							}
						} else {
							hides[x][y] = hides[x - 1][y];
						}
					}
				}
			}
			break;
		case 34:
			if (x == 1) {
				hides[x][y] = datas[x - 1][19];// U5
			} else {// cur = B07
					// =IF(ISBLANK(A7);"";IF(BR7="FTL";IF($A6=0;$U5;$U6);IF($A6=0;$U4;$U5)))
				hides[x][y] = (hides[x][y - 1].equals(FTL)) ? ((colA[x - 1] == 0) ? (datas[x - 2][19])
						: (datas[x - 1][19]))
						: ((colA[x - 1] == 0) ? (datas[x - 3][19])
								: (datas[x - 2][19]));
			}
			break;
		case 35:
			// =IF($A6=0;"N";IF(BO6=$U6;"Y";"N"))
			if (colA[x] == 0) {
				hides[x][y] = N;
			} else {
				if (hides[x][y - 1].equals(datas[x][19])) {// L6
					hides[x][y] = Y;
				} else {
					hides[x][y] = N;
				}
			}
			break;
		}
	}

	private boolean getHidesCondition13(int x, int y) {
		// AND(
		// AZ6="N";
		// AX6<>"BBL";
		// IF(
		// COUNTIF($A5:$A7;0)=1;
		// AND(AZ5="N";AX5<>"BBL");
		// TRUE
		// );
		// IF(
		// COUNTIF($A5:$A7;0)=2;
		// AND(AZ5="N";AZ4="N";AX5<>"BBL";AX4<>"BBL");
		// TRUE
		// )
		// );
		boolean result = false;
		if (x == 2) {// cur = AX7
			result = hides[x - 2][y + 2].equals(N)
					&& !hides[x - 2][y].equals(BBL)
					&& ((countIfColA(x - 3, x - 1, 0) == 1) ? (hides[x - 3][y + 2]
							.equals(N) && hides[x - 3][y].equals(BBL)) : true)
					&& ((countIfColA(x - 3, x - 1, 0) == 2) ? (hides[x - 3][y + 2]
							.equals(N)
							&& "".equals(N)
							&& !hides[x - 3][y].equals(BBL) && !"".equals(BBL))
							: true);
		} else {// cur = AX8
			result = hides[x - 2][y + 2].equals(N)
					&& !hides[x - 2][y].equals(BBL)
					&& ((countIfColA(x - 3, x - 1, 0) == 1) ? (hides[x - 3][y + 2]
							.equals(N) && hides[x - 3][y].equals(BBL)) : true)
					&& ((countIfColA(x - 3, x - 1, 0) == 2) ? (hides[x - 3][y + 2]
							.equals(N)
							&& hides[x - 4][y + 2].equals(N)
							&& !hides[x - 3][y].equals(BBL) && !hides[x - 4][y]
							.equals(BBL)) : true);
		}
		Log.e("getHidesCondition13 at " + x + " " + y, "" + result);
		return result;
	}

	private boolean getHidesCondition25(int x, int y) {
		// AND(
		// BL5="N";
		// BL4="N";
		// BJ5<>"BBL";
		// BJ4<>"BBL";
		// IF(
		// COUNTIF($A3:$A6;0)=1;
		// AND(BL3="N";BJ3<>"BBL");
		// TRUE)
		// ;IF(
		// COUNTIF($A2:$A6;0)=2;
		// AND(BL3="N";BJ3<>"BBL";BL2="N";BJ2<>"BBL");
		// TRUE
		// )
		// )
		boolean result = false;
		if (x == 2) {// alway false
			return result;
		}
		if (x == 3) {
			result = hides[x - 2][y + 2].equals(N)
					&& hides[x - 3][y + 2].equals(N)
					&& !hides[x - 2][y].equals(BBL)
					&& !hides[x - 3][y].equals(BBL)
					&& ((countIfColA(0, x - 1, 0) == 1) ? ("".equals(N) && !""
							.equals(BBL)) : true)
					&& ((countIfColA(0, x - 1, 0) == 2) ? ("".equals(N)
							&& !"".equals(BBL) && "".equals(N) && !""
							.equals(BBL)) : true);
			return result;
		}
		if (x == 4) {
			result = hides[x - 2][y + 2].equals(N)
					&& hides[x - 3][y + 2].equals(N)
					&& !hides[x - 2][y].equals(BBL)
					&& !hides[x - 3][y].equals(BBL)
					&& ((countIfColA(x - 4, x - 1, 0) == 1) ? (hides[x - 4][y + 2]
							.equals(N) && !hides[x - 4][y].equals(BBL)) : true)
					&& ((countIfColA(0, x - 1, 0) == 2) ? (hides[x - 4][y + 2]
							.equals(N)
							&& !hides[x - 4][y].equals(BBL)
							&& "".equals(N) && !"".equals(BBL)) : true);
			return result;
		}
		if (x >= 5) {// cur = BJ7, x = 2
			result = hides[x - 2][y + 2].equals(N)
					&& hides[x - 3][y + 2].equals(N)
					&& !hides[x - 2][y].equals(BBL)
					&& !hides[x - 3][y].equals(BBL)
					&& ((countIfColA(x - 4, x - 1, 0) == 1) ? (hides[x - 4][y + 2]
							.equals(N) && !hides[x - 4][y].equals(BBL)) : true)
					&& ((countIfColA(x - 5, x - 1, 0) == 2) ? (hides[x - 4][y + 2]
							.equals(N)
							&& !hides[x - 4][y].equals(BBL)
							&& hides[x - 5][y + 2].equals(N) && !hides[x - 5][y]
							.equals(BBL))
							: true);
		}
		Log.e("getHidesCondition25 at " + x + " " + y, "" + result);
		return result;
	}

	private String getDatasCondition5(int x, int y) {
		String result = "";
		switch (x) {
		case 2:
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? ("")
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][1])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? ("")
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? ("")
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? ("")
													: (datas[x - 2][1])))));
			break;
		case 3:
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? ("")
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][1])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? ("")
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? ("")
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? (datas[x - 3][1])
													: (datas[x - 2][1])))));
			break;
		case 4:
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? ("")
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][1])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? ("")
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? (datas[x - 4][1])
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? (datas[x - 3][1])
													: (datas[x - 2][1])))));
			break;
		case 5:
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? ("")
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][1])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? (datas[x - 5][1])
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? (datas[x - 4][1])
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? (datas[x - 3][1])
													: (datas[x - 2][1])))));
			break;
		default:
			// =IF(
			// COUNTIF($A4:$A6;0)=3;
			// C1;
			// IF(
			// COUNTIF($A5:$A6;0)=0;
			// C5;
			// IF(
			// COUNTIF($A4:$A6;0)=3;
			// C2;
			// IF(
			// COUNTIF($A4:$A6;0)=2;
			// C3;
			// IF(COUNTIF($A4:$A6;0)=1;C4;C5))
			// )
			// )
			// );
			// cur = G7
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? (datas[x - 6][1])
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][1])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? (datas[x - 5][1])
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? (datas[x - 4][1])
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? (datas[x - 3][1])
													: (datas[x - 2][1])))));
			break;
		}
		return result;
	}
	private String getDatasCondition10(int x, int y) {
		String result = "";
		switch (x) {
		case 2:
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? ("")
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][10])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? ("")
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? ("")
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? ("")
													: (datas[x - 2][10])))));
			break;
		case 3:
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? ("")
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][10])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? ("")
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? ("")
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? (datas[x - 3][10])
													: (datas[x - 2][10])))));
			break;
		case 4:
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? ("")
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][10])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? ("")
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? (datas[x - 4][10])
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? (datas[x - 3][10])
													: (datas[x - 2][10])))));
			break;
		case 5:
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? ("")
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][10])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? (datas[x - 5][10])
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? (datas[x - 4][10])
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? (datas[x - 3][10])
													: (datas[x - 2][10])))));
			break;
		default:
			// =IF(
			// COUNTIF($A4:$A6;0)=3;
			// C1;
			// IF(
			// COUNTIF($A5:$A6;0)=0;
			// C5;
			// IF(
			// COUNTIF($A4:$A6;0)=3;
			// C2;
			// IF(
			// COUNTIF($A4:$A6;0)=2;
			// C3;
			// IF(COUNTIF($A4:$A6;0)=1;C4;C5))
			// )
			// )
			// );
			// cur = G7
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? (datas[x - 6][10])
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][10])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? (datas[x - 5][10])
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? (datas[x - 4][10])
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? (datas[x - 3][10])
													: (datas[x - 2][10])))));
			break;
		}
		return result;
	}
	private String getDatasCondition19(int x, int y) {
		String result = "";
		switch (x) {
		case 2:
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? ("")
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][19])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? ("")
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? ("")
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? ("")
													: (datas[x - 2][19])))));
			break;
		case 3:
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? ("")
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][19])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? ("")
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? ("")
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? (datas[x - 3][19])
													: (datas[x - 2][19])))));
			break;
		case 4:
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? ("")
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][19])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? ("")
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? (datas[x - 4][19])
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? (datas[x - 3][19])
													: (datas[x - 2][19])))));
			break;
		case 5:
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? ("")
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][19])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? (datas[x - 5][19])
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? (datas[x - 4][19])
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? (datas[x - 3][19])
													: (datas[x - 2][19])))));
			break;
		default:
			// =IF(
			// COUNTIF($A4:$A6;0)=3;
			// C1;
			// IF(
			// COUNTIF($A5:$A6;0)=0;
			// C5;
			// IF(
			// COUNTIF($A4:$A6;0)=3;
			// C2;
			// IF(
			// COUNTIF($A4:$A6;0)=2;
			// C3;
			// IF(COUNTIF($A4:$A6;0)=1;C4;C5))
			// )
			// )
			// );
			// cur = G7
			result = (countIfColA(x - 3, x - 1, 0) == 3) ? (datas[x - 6][19])
					: ((countIfColA(x - 2, x - 1, 0) == 0) ? (datas[x - 2][19])
							: ((countIfColA(x - 3, x - 1, 0) == 3) ? (datas[x - 5][19])
									: ((countIfColA(x - 3, x - 1, 0) == 2) ? (datas[x - 4][19])
											: ((countIfColA(x - 3, x - 1, 0) == 1) ? (datas[x - 3][19])
													: (datas[x - 2][19])))));
			break;
		}
		return result;
	}

	private int countIfColA(int sta, int end, int criteria) {
		int result = 0;
		if (sta < 0) {
			sta = 0;
		}
		if (end > MAX_ROW) {
			end = MAX_ROW;
		}
		if (sta > end) {
			return 0;
		}
		for (int i = sta; i <= end; i++) {
			if (colA[i] == criteria) {
				result++;
			}
		}
		// Log.e("From " + sta +" to " + end, result +"");
		return result;
	}

	private void showtest(int row) {
		String strA = "colA = ";
		for (int i = 0; i < row; i++) {
			if (colA[i] == -1) {
				continue;
			}
			strA = strA + colA[i];
		}
		Log.e("colA = ", strA);
		for (int i = 0; i < row; i++) {
			String str = "";
			for (int j = 0; j < 36; j++) {
				str = str + String.format("%3s|", datas[i][j]);
			}
			str = str + "***";
			// for (int j = 10; j < 20; j++) {
			// str = str + String.format("%3s|", hides[i][j]);
			// }
			Log.e("At row " + i, str);
		}
	}

	public boolean isE(String str) {
		return TextUtils.isEmpty(str);
	}

	public double[] getRedBlack_1S() {
		Log.e("curMax = ", " = " + curMaxIndex);
		double[] result = new double[curMaxIndex];
		for (int i = 0; i < curMaxIndex; i++) {
			if (TextUtils.isEmpty(datas[i][2])) {
				result[i] = 0;
			} else {
				result[i] = Integer.parseInt(datas[i][2]);
				Log.e("result[i] = ", "= " + Integer.parseInt(datas[i][2]));
			}
		}
		return result;
	}

	public Number[] getRedBlack_11S() {
		Log.e("curMax = ", " = " + curMaxIndex);
		Number[] result = new Number[curMaxIndex];
		for (int i = 0; i < curMaxIndex; i++) {
			if (TextUtils.isEmpty(datas[i][2])) {
				result[i] = 0;
			} else {
				result[i] = Integer.parseInt(datas[i][2]);
				Log.e("result[i] = ", "= " + Integer.parseInt(datas[i][2]));
			}
		}
		return result;
	}

	public double[] getRedBlack_2S() {
		double[] result = new double[curMaxIndex];
		for (int i = 0; i < curMaxIndex; i++) {
			if (TextUtils.isEmpty(datas[i][3])) {
				result[i] = 0;
			} else {
				result[i] = Integer.parseInt(datas[i][3]);
			}
		}
		return result;
	}

	public double[] getRedBlack_3S() {
		double[] result = new double[curMaxIndex];
		for (int i = 0; i < curMaxIndex; i++) {
			if (TextUtils.isEmpty(datas[i][4])) {
				result[i] = 0;
			} else {
				result[i] = Integer.parseInt(datas[i][4]);
			}
		}
		return result;
	}

	public double[] getRedBlack_BBL() {
		double[] result = new double[curMaxIndex];
		for (int i = 0; i < curMaxIndex; i++) {
			if (TextUtils.isEmpty(datas[i][5])) {
				result[i] = 0;
			} else {
				result[i] = Integer.parseInt(datas[i][5]);
			}
		}
		return result;
	}

	public double[] getRedBlack_FTL() {
		double[] result = new double[curMaxIndex];
		for (int i = 0; i < curMaxIndex; i++) {
			if (TextUtils.isEmpty(datas[i][6])) {
				result[i] = 0;
			} else {
				result[i] = Integer.parseInt(datas[i][6]);
			}
		}
		return result;
	}
	public double[] getRedBlack_ARD() {
		double[] result = new double[curMaxIndex];
		for (int i = 0; i < curMaxIndex; i++) {
			if (TextUtils.isEmpty(datas[i][7])) {
				result[i] = 0;
			} else {
				result[i] = Integer.parseInt(datas[i][7]);
			}
		}
		return result;
	}
	public double[] getRedBlack_ABK() {
		double[] result = new double[curMaxIndex];
		for (int i = 0; i < curMaxIndex; i++) {
			if (TextUtils.isEmpty(datas[i][8])) {
				result[i] = 0;
			} else {
				result[i] = Integer.parseInt(datas[i][8]);
			}
		}
		return result;
	}

	public void clearData() {

		initData();
	}
}
